package com.tuanzi.loan.web.bean.templateConf;

import com.tuanzi.loan.business.service.templateConf.TemplateItemService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.templateConf.TemplateItemRequest;
import com.tuanzi.loan.vo.response.templateConf.TemplateItemResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.templateConf.TemplateItemLazyDataModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;

/**
 * 资料填写模板项配置
 */
@Debug
@Component
@ViewScoped
public class TemplateItemListBean extends JSFListingSessionBean<TemplateItemRequest, TemplateItemResponse> {

    private static final long serialVersionUID = -7456998959122405455L;

    @Autowired
    private TemplateItemService templateItemService;

    public void onReset() {
        initLazyDataModel();
    }

    public String onAdd() {
        return redirect("/views/templateConf/itemConf/iteminfo.xhtml");
    }

    public String onEdit(Long id) {
        return redirect("/views/templateConf/itemConf/iteminfo?id=" + id);
    }

    public String onSecondItem(Long id) {
        return redirect("/views/templateConf/itemConf/seconditeminfo?id=" + id);
    }

    public void onDelete(Long id) {
        templateItemService.delete(id);
    }

    @Override
    protected String page() {
        return "/views/templateConf/itemConf/itemlist.xhtml";
    }

    @Override
    protected void initLazyDataModel() {
        $ = new TemplateItemRequest();
        lazyDataModel = new TemplateItemLazyDataModel($, session, templateItemService);
    }
}
